﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ViewCamera.CApVCDisplayCameraEnvelopeEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.ViewCamera;

public class CApVCDisplayCameraEnvelopeEnabler : ITxCommandEnabler
{
  private readonly CApVCDisplayCameraEnvelopeCmd _cmd;

  public CApVCDisplayCameraEnvelopeEnabler(CApVCDisplayCameraEnvelopeCmd cmd) => this._cmd = cmd;

  public bool Enable => this.ShouldEnable();

  private bool ShouldEnable()
  {
    bool flag = false;
    bool pressed = false;
    int totalCount = TxApplication.ActiveSelection.TotalCount;
    if (totalCount > 0 && TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDocumentLoaded())
    {
      TxObjectList filteredItems = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) new TxTypeFilter(typeof (TxViewCamera)));
      if (((Collection<ITxObject>) filteredItems).Count == totalCount && this._cmd != null && this._cmd.App != null)
      {
        flag = true;
        pressed = true;
        foreach (TxViewCamera camera in (Collection<ITxObject>) filteredItems)
        {
          if (!this._cmd.App.HasDisplayedCameraEnvelope(camera))
          {
            pressed = false;
            break;
          }
        }
      }
    }
    this.UpdateCommandPressedState(pressed);
    return flag;
  }

  private void UpdateCommandPressedState(bool pressed)
  {
    if (this._cmd == null)
      return;
    this._cmd.Pressed = pressed;
  }
}
